package com.channel.temperature.collect.ui.adapter

import android.util.SparseArray
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.channel.temperature.collect.ui.fragment.DataHandleFragment
import com.channel.temperature.collect.ui.fragment.OnlineCollectFragment
import com.channel.temperature.collect.ui.fragment.SettingFragment
import com.channel.temperature.collect.ui.fragment.TaskFragment

class CollectHomeAdapter(fa: FragmentActivity) : FragmentStateAdapter(fa) {

    companion object {
        const val PAGE_Task = 0
        const val PAGE_Online = 1
        const val PAGE_Data = 2
        const val PAGE_Setting = 3
    }

    private val fragments: SparseArray<Fragment> = SparseArray()

    init {
        fragments.put(PAGE_Task, TaskFragment.newInstance())
        fragments.put(PAGE_Online, OnlineCollectFragment.newInstance())
        fragments.put(PAGE_Data, DataHandleFragment.newInstance())
        fragments.put(PAGE_Setting, SettingFragment.newInstance())
    }

    override fun createFragment(position: Int): Fragment {
        return fragments[position]
    }

    override fun getItemCount(): Int {
        return fragments.size()
    }
}